﻿using System;

namespace Extension {
  public static class LinqExt {
    /// <summary>
    /// 判断某个值是否在给定的区间内，默认为：包含下界，不包含上界(即[lowerBound,upperBound))
    /// </summary>
    /// <typeparam name="T">可比较类型<see cref="IComparable{T}"/></typeparam>
    /// <param name="t"></param>
    /// <param name="lowerBound">下界</param>
    /// <param name="upperBound">上界</param>
    /// <param name="includeLowerBound">是否包含下界</param>
    /// <param name="includeUpperBound">是否包含上界</param>
    /// <returns></returns>
    public static bool IsBetween<T>(this T t, T lowerBound, T upperBound, bool includeLowerBound = true,
      bool includeUpperBound = false) where T : IComparable<T> {
      if (t == null) throw new ArgumentNullException();

      var lowerCompareResult = t.CompareTo(lowerBound);
      var upperCompareResult = t.CompareTo(upperBound);

      return (includeLowerBound && lowerCompareResult == 0)
             || (includeUpperBound && upperCompareResult == 0)
             || (lowerCompareResult > 0 && upperCompareResult < 0);
    }

    public static bool LessThan<T>(this T t, T lowerBound, T upperBound, bool includeLowerBound = true,
      bool includeUpperBound = false) where T : IComparable<T> {
      throw new NotImplementedException();
    }
    public static bool LessOrEquals<T>(this T t, T lowerBound, T upperBound, bool includeLowerBound = true,
      bool includeUpperBound = false) where T : IComparable<T> {
      throw new NotImplementedException();
    }
    public static bool GreatOrEquals<T>(this T t, T lowerBound, T upperBound, bool includeLowerBound = true,
      bool includeUpperBound = false) where T : IComparable<T> {
      throw new NotImplementedException();
    }
    public static bool GreatThan<T>(this T t, T lowerBound, T upperBound, bool includeLowerBound = true,
     bool includeUpperBound = false) where T : IComparable<T> {
      throw new NotImplementedException();
    }

  }
}
